package freshmanspecial.mredrock.com.welcomefreshman.Fragment;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;


import freshmanspecial.mredrock.com.welcomefreshman.Adapter.TrainRecyclerAdapter;
import freshmanspecial.mredrock.com.welcomefreshman.Base.BaseFragment;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.MilitaryTrainingPhotoBean;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.MilitaryTrainingVideoBean;
import freshmanspecial.mredrock.com.welcomefreshman.Model.TrainModel;
import freshmanspecial.mredrock.com.welcomefreshman.R;

/**
 * Created by Administrator on 2017/8/9 0009.
 */

public class TrainMienFragment extends BaseFragment {
    private ImageView video1,video2;
    private TextView video_title1,video_title2;
    private ImageButton btn_vedio1,btn_video2;
    private RecyclerView recyclerView;
    private TrainRecyclerAdapter adapter;
    private MilitaryTrainingPhotoBean bean ;
    @Override
    protected void addDefaultData() {
        TrainModel trainModel = new TrainModel();
        trainModel.getTrainingVideo(new TrainModel.OnGetTrain() {
            @Override
            public void onFinish(Object dataBean) {
                MilitaryTrainingVideoBean bean = (MilitaryTrainingVideoBean) dataBean;
                Glide.with(getActivity()).load(bean.getData().get(0).getCover()).into(video1);
                Glide.with(getActivity()).load(bean.getData().get(1).getCover()).into(video2);
                video_title1.setText(bean.getData().get(0).getTitle());
                video_title2.setText(bean.getData().get(1).getTitle());
                setVideoPlay(bean);
            }
        });
        trainModel.getTrainingPhoto(new TrainModel.OnGetTrain() {
            @Override
            public void onFinish(Object dataBean) {
                bean = (MilitaryTrainingPhotoBean) dataBean;
                adapter = new TrainRecyclerAdapter(bean,getActivity());
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
                linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                recyclerView.setAdapter(adapter);
            }
        });
    }

    @Override
    protected void initView() {
        recyclerView = $(R.id.train_rv);
        video1 = $(R.id.train_video1);
        video2 = $(R.id.train_video2);
        video_title1 = $(R.id.video_title1);
        video_title2 = $(R.id.video_title2);
        btn_vedio1 = $(R.id.btn_video1);
        btn_video2 = $(R.id.btn_video2);
    }
    private void setVideoPlay(final MilitaryTrainingVideoBean bean){
        btn_vedio1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Uri uri = Uri.parse(bean.getData().get(0).getUrl());
                Intent intent = new Intent(Intent.ACTION_VIEW,uri);
                getActivity().startActivity(intent);
            }
        });
        btn_video2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Uri uri = Uri.parse(bean.getData().get(1).getUrl());
                Intent intent = new Intent(Intent.ACTION_VIEW,uri);
                getActivity().startActivity(intent);
            }
        });
    }
    @Override
    protected int getResourceId() {
        return R.layout.special_2017_train_mien_fragment;
    }
}
